package com.zam.web.sysController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.zam.comment.Constants;
import com.zam.comment.Result;
import com.zam.pojo.Dict;
import com.zam.service.IDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/******************************
 controller层
 ******************************/
@RestController
@RequestMapping("/dict")
public class DictController {
    @Autowired
    private IDictService dictService;

    /*
    添加数据
    */
    @PostMapping
    public boolean save(@RequestBody Dict dict) {
        return dictService.saveOrUpdate(dict);
    }

    /*
    删除数据
    */
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Integer id) {
        return dictService.removeById(id);
    }

    /*
    删除多个数据
    */
    @DeleteMapping("/del/batch")
    public boolean deleteBatch(@RequestBody List<Integer> ids) {
        return dictService.removeByIds(ids);
    }

    /*
     查看全部
    */
    @GetMapping
    public List<Dict> findAll() {
        return dictService.list();
    }

    @GetMapping("/icon")
    public Result findAllDict() {
        LambdaQueryWrapper<Dict> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Dict::getType, Constants.DICT_TYPE_ICON);
        return Result.success(dictService.list(lambdaQueryWrapper));
    }
    /*
    根据id查看
    */
    @GetMapping("/{id}")
    public Dict findOne(@PathVariable Integer id) {
        return dictService.getById(id);
    }
}

